#include <iostream>
using namespace std;

int main() {
    string str;
    cin >> str;
    int ret=1e9;
    for(char s='a';s<='z';s++)
    {
        int sum=0;
        for(int i=0;i<str.size();i++)
        {
            sum+=min(abs(s-str[i]),26-abs(s-str[i]));
        }
        ret=min(ret,sum);
    }
    cout << ret << endl;
    return 0;
}